#include <algorithm>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param triangle int整型vector<vector<>> 
     * @return int整型
     */
    int minTrace(vector<vector<int> >& triangle) {
        // write code here
        int m = triangle.size();
        vector< vector<int> > dp(m, vector<int>(m, 0));
        for(int i = 0; i < m; i++) dp[m-1][i] = triangle[m-1][i];

        for(int i = m-2; i >= 0; i--){
            for(int j = 0; j <= i ;j++){
                dp[i][j] = triangle[i][j] + min(dp[i+1][j], dp[i+1][j+1]);
            } 
        }
        return dp[0][0];
    }
};